from argparse import ArgumentParser
from pathlib import Path


def parse_args(text=None, known_args_only=False):
    """Parse the arguments from the text or command line"""
    parser = ArgumentParser()
    # yapf: disable
    parser.add_argument("-m", "--model-path", type=Path, help="Path to model file to initialize from.")
    parser.add_argument("-g", "--gpu", type=int, default=-1, help="GPU ID to use. -1 for auto.")
    parser.add_argument("--debug", action="store_true", help="Enable debug mode.")
    parser.add_argument("--no-half", action="store_true", help="Disable FP16.")
    parser.add_argument("--no-auth", action="store_true", help="Disable authentication.")
    parser.add_argument("--config", type=Path, help="Path to the config file.", default="config.yaml")
    # yapf: enable

    if known_args_only:
        return parser.parse_known_args(text)[0]
    else:
        return parser.parse_args(text)
